package com.fanghuyun.iswaf.common;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.regex.Pattern;

import com.fanghuyun.iswaf.function.WebShell;

public class DirectoryScan {
	
	private static List<String> ls = new ArrayList<String>();
	
	public List<String> getFile(String path){
		try {
			SysConfig config = new SysConfig();
			Properties properties = config.getSysConfigProperties();
			File f = new File(path);
			String[] s = f.list();
			for(String str :s){
				String fls = path.endsWith("/")?path+str:path+"/";
				if(new File(fls).isDirectory()){
					getFile(fls);
				}else{
					if(Pattern.compile("^(.*)\\.("+(properties.getProperty("function.webshell.suffix"))+")$",Pattern.CASE_INSENSITIVE).matcher(str).find()){
						if(!WebShell.isWebShell(new File(path+str),properties)){
							ls.add(path+str+"\n");
						}
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ls;
	}
	
	public static void main(String[] args) {
		DirectoryScan ds = new DirectoryScan();
		List<String> ls = ds.getFile("E:/Src/API/Cms/");
		for(String s : ls){
			System.out.println(s);
		}
	}
	
}
